<template>
  <div>
    <FormPanel ref="formpanel1" :list="formList1" :cols="4" :isSubmitBtn="false" @formChange="formchangeFun" />
    <div style="text-align: center;">
      <el-button type="primary" @click="FormPanelSeacher">查询</el-button>
      <el-button @click="FormPanelreset">重置</el-button>
    </div>
    <el-row :gutter="10">
      <el-col :span="16">
        <FilterTable
          ref="basetable"
          :columns="columns"
          :fetchapi="fetchApi"
          :params="fetchParams"
          :datakey="'rows'"
          :onColumnsChange="columns => (this.columns = columns)"
          :height="'200'"
          :isSelectColumn="false"
          :dataSource="toptablelistSource"
          :onEnterEvent="tableDbclickFun"
          :rowstyles="styleList"
          selectionType="single"
          columnsRef="partExchangePlatformTabsSalesOrderAdd"
        ></FilterTable>
      </el-col>
      <el-col :span="8">
        <FilterTable
          ref="tablehistory"
          :columns="rigcolumns"
          :onColumnsChange="columns => (this.rigcolumns = columns)"
          :isSelectColumn="false"
          :datakey="'rows'"
          :height="'200'"
          :dataSource="rigtablelistSource"
          selectionType="single"
          columnsRef="partExchangePlatformTabsSalesOrderAdd1"
        ></FilterTable>
      </el-col>
    </el-row>

    <FormPanel ref="formpanel2" :list="formList2" :cols="4" :isSubmitBtn="false" @formChange="formchangeFuns" />
    <FilterTable
      ref="basetables"
      :columns="columns1"
      :dataSource="tablelistSource"
      :isSelectColumn="false"
      :datakey="'rows'"
      :onColumnsChange="columns1 => (this.columns1 = columns1)"
      :height="'200'"
      :onSyncTableData="tablechangeFun"
      columnsRef="partExchangePlatformTabsSalesOrderAdd2"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9999,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'center'
      }"
    >
      <el-button type="primary" @click="confirmHandle">添加</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { StockParts, Storage, queryBrand, salesHistory } from '@/api/part/partOut/partSales/index';
import { getStroageList } from '@/api/part/partOutbound/partBreak';
import { findAllRepair } from '@/api/repair/basicParameters';
import { log } from 'util';
export default {
  name: '',
  mixins: [dictionary],
  props: ['customerCode', 'priceAddRate', 'salesBasePriceType', 'rate'],
  data() {
    this.basetable = null;
    this.basetables = null;
    this.tablehistory = null;
    this.searchstore();
    return {
      formList1: this.createFrom(),
      formList2: this.createFroms(),
      fetchApi: StockParts,
      fetchParams: {
        xhrAbort: true
      },
      SALES_PRICE: null,
      columns: this.createTable(),
      columns1: this.createTables(),
      rigcolumns: this.createtightTable(),
      tablelistSource: [],
      toptablelistSource: [],
      tableslist: [],
      rigtablelistSource: [],
      listRecive: [], // 定义接收数据
      listType: [],
      styleList: [],
      flagS: '', // 表单提交控制校验的状态
      typePrice: 0,
      listPrice: 0, // 价格
      getpartParams: {
        sort: 'STORAGE_CODE',
        STORAGE_CODE: '',
        PART_NO: '',
        CUSTOMER_CODE: ''
      },
      fromSubmitdata: {}
    };
  },
  mounted() {
    this.basetable = this.$refs.basetable.$refs.pageTable;
    this.basetables = this.$refs.basetables.$refs.pageTable;
    this.tablehistory = this.$refs.tablehistory.$refs.pageTable;
    this.queryBrand();
  },
  methods: {
    createFrom() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'storageCode',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brand',
          itemList: []
        },
        {
          type: 'SELECT',
          label: '配件类别',
          fieldName: 'partGroupCode',
          itemList: this.createDictList('8075')
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PartNo'
        },
        {
          type: 'INPUT',
          label: '拼音代码',
          fieldName: 'spellCode'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName'
        },
        {
          type: 'INPUT',
          label: '库位',
          fieldName: 'storagePositionCode'
        },
        {
          type: 'SELECT',
          label: '库存大于零',
          fieldName: 'stockZero',
          initialValue: '10041001',
          itemList: [{ text: '是', value: '10041001' }]
        },
        {
          type: 'SELECT',
          label: '售价大于零',
          fieldName: 'priceZero',
          itemList: [{ text: '是', value: '10041001' }]
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'description'
        }
      ];
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.STORAGE_CODE}</span>;
          }
        },
        {
          title: '库位',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.STORAGE_POSITION_CODE}</span>;
          }
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.PART_NO}</span>;
          }
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.PART_NAME}</span>;
          }
        },
        {
          title: '销售价',
          dataIndex: 'SALES_PRICE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.SALES_PRICE}</span>;
          }
        },
        {
          title: '账面库存',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.STOCK_QUANTITY}</span>;
          }
        },
        {
          title: '最新进货价',
          dataIndex: 'LATEST_PRICE',
          sorter: true,
          render: props => {
            return <span>{props.row.LATEST_PRICE}</span>;
          }
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.REMARK}</span>;
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '成本价',
          fieldName: 'COST_PRICE',
          hidden: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '网点价',
          fieldName: 'NODE_PRICE',
          hidden: true
        }
      ];
    },
    createtightTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '销售日期',
          dataIndex: 'SEND_TIME',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true,
          filter: true
        },
        {
          title: '销售单价',
          dataIndex: 'PART_SALES_PRICE',
          sorter: true,
          filter: true
        },
        {
          title: '销售金额',
          dataIndex: 'SALES_AMOUNT',
          sorter: true,
          filter: true
        },
        {
          title: '客户名称',
          dataIndex: 'CUSTOMER_NAME',
          sorter: true,
          filter: true
        },
        {
          title: '出库日期',
          dataIndex: 'FINISHED_DATE',
          sorter: true,
          filter: true,
          dateFormat: 'yyyy-MM-dd'
        }
      ];
    },
    createFroms() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'STORAGE_CODE',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PART_NO',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'PART_NAME',
          disabled: false
        },
        {
          type: 'SELECT',
          label: '价格类型',
          fieldName: 'PRICE_TYPE',
          initialValue: this.salesBasePriceType ? this.salesBasePriceType : 80501002,
          itemList: this.createDictList('8050'),
          change: val => {
            this.changeType(val);
          }
        },
        {
          type: 'INPUT_NUMBER',
          label: '价格系数',
          fieldName: 'PRICE_RATE',
          min: 0,
          max: 9.99,
          precision: 2,
          initialValue: this.priceAddRate,
          rules: [{ required: true, message: '请输入价格系数', trigger: 'blur' }],
          change: val => {
            this.changecoefficient(val);
          }
        },

        {
          type: 'INPUT_NUMBER',
          label: '发料单价',
          fieldName: 'PART_SALES_PRICE',
          initialValue: 0,
          precision: 2,
          rules: [{ required: true }],
          change: val => {
            this.changeMoney(val);
          }
        },
        {
          type: 'INPUT',
          label: '发料数量',
          fieldName: 'PART_QUANTITY',
          initialValue: 1,
          change: val => {
            this.changemNum(val);
          }
        },
        {
          type: 'INPUT',
          label: '发料金额',
          fieldName: 'SALES_AMOUNT',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '销售方式',
          fieldName: 'SALES_TYPE',
          initialValue: 80961001,
          itemList: this.createDictList('8096')
        }
      ];
    },
    createTables() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '销售价',
          dataIndex: 'SALES_PRICE',
          sorter: true,
          filter: true
        },
        {
          title: '索赔价',
          dataIndex: 'CLAIM_PRICE',
          sorter: true
        },
        {
          title: '终端建议零售价格',
          dataIndex: 'INSURANCE_PRICE',
          sorter: true,
          filter: true
        },
        {
          title: '销售限价',
          dataIndex: 'LIMIT_PRICE',
          sorter: true,
          filter: true
        },
        {
          title: '账面库存',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true
        },
        {
          title: '可用库存',
          dataIndex: 'USEABLE_STOCK',
          sorter: true,
          filter: true
        },
        {
          title: '锁定量',
          dataIndex: 'LOCKED_QUANTITY',
          sorter: true,
          filter: true
        },
        {
          title: '替代配件',
          dataIndex: 'OPTION_NO',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.OPTION_NO ? props.row.OPTION_NO : ''}</span>;
          }
        },
        {
          title: '替代件库存',
          dataIndex: 'OPTION_STOCK',
          sorter: true
        },
        {
          title: '配件类别',
          dataIndex: 'PART_GROUP_CODE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.PART_GROUP_CODE, '8075')}</span>;
          }
        },
        {
          title: '单位',
          dataIndex: 'UNIT_NAME',
          sorter: true,
          filter: true
        },
        {
          title: '单位CODE',
          dataIndex: 'UNIT_CODE',
          sorter: true,
          filter: true,
          hidden: true
        },
        {
          title: '最新进货价',
          dataIndex: 'LATEST_PRICE',
          hidden: true
        }
      ];
    },
    // 品牌下拉框
    async queryBrand() {
      const res = await queryBrand();
      this.formList1.find(item => item.fieldName === 'brand').itemList = res.data.map(x => ({ value: x.brandId, text: x.brandName }));
    },
    // 仓库下拉框
    async searchstore() {
      try {
        const res = await getStroageList();
        this.formList1.find(item => item.fieldName === 'storageCode').itemList = res.data.map(x => ({ value: x.STORAGE_CODE, text: x.STORAGE_NAME }));
      } catch (err) {
        console.log(err);
      }
      try {
        let resdata = await findAllRepair();
        this.formList1.find(item => item.fieldName === 'storageCode').initialValue = resdata.data['1100'];
      } catch (err) {
        console.log(err);
      }
    },

    // 重置
    FormPanelreset() {
      this.$refs.formpanel1.RESET_FORM();
    },
    FormPanelSeacher() {
      this.$refs.formpanel1.SUBMIT_FORM();
    },
    formchangeFun(val) {
      const params = Object.assign({}, val, { xhrAbort: false });
      this.fetchParams = params;
    },
    formchangeFuns(val) {
      this.fromSubmitdata = val;
      this.flagS = true;
    },

    tableDbclickFun(val) {
      // 清空上一次的值
      this.tablelistSource = []; // 对table里面值进行清空
      this.styleList = []; // 清空上次定义的样式
      this.rigtablelistSource = []; // 清空上次的历史查询记录
      this.listRecive = [];
      this.listType = val;
      this.styleList.push({ row: val, styles: { backgroundColor: '#F9E491' } });
      if (val.DOWN_TAG == 10041001) {
        this.formList2.find(item => item.fieldName === 'PART_NAME').disabled = true;
      } else {
        this.formList2.find(item => item.fieldName === 'PART_NAME').disabled = false;
      }
      this.formList2.find(item => item.fieldName === 'STORAGE_CODE').initialValue = val.STORAGE_CODE;
      this.formList2.find(item => item.fieldName === 'PART_NO').initialValue = val.PART_NO;
      this.formList2.find(item => item.fieldName === 'PART_NAME').initialValue = val.PART_NAME;
      this.formList2.find(item => item.fieldName === 'PRICE_TYPE').initialValue = this.salesBasePriceType ? this.salesBasePriceType : 80501002;
      this.formList2.find(item => item.fieldName === 'PRICE_RATE').initialValue = this.priceAddRate ? this.priceAddRate : 1;
      this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.numFilter(val.SALES_PRICE);
      this.formList2.find(item => item.fieldName === 'PART_QUANTITY').initialValue = 1;
      this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(val.SALES_PRICE);

      // 第一次默认取的销售价的值
      this.listPrice = this.numFilter(val.SALES_PRICE);
      this.getSalesHistory(val);
      this.tablelistSource = [val];
    },
    async getSalesHistory(val) {
      let res = await salesHistory(val.STORAGE_CODE, val.PART_NO, this.customerCode);
      this.tablehistory.EXECUTE_INSERT(res.data.rows);
    },

    // 校验单价
    checkPrice(rule, value, callback) {
      if (!value) {
        return callback(new Error(rule.message));
      } else {
        const reg = /^([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error(rule.message));
        }
      }
      callback();
    },
    // 校验数量
    checkNum(rule, value, callback) {
      let res = String(value).split('.');
      let num = 0;
      if (res[1] != undefined) {
        num = res[1].length;
      }
      if (!value) {
        return this.$notify.success({ title: '提示信息', message: rule.message });
      } else {
        if (value >= 0 && num <= 2) {
          callback();
        } else {
          return this.$notify.success({ title: '提示信息', message: rule.message });
        }
      }
      callback();
    },
    // 校验系数
    checkRate(rule, value, callback) {
      // 获取小数位的长度
      let res = String(value).split('.');
      let num = 0;
      if (res[1] != undefined) {
        num = res[1].length;
      }
      if (!value) {
        return this.$notify.success({ title: '提示信息', message: rule.message });
      } else {
        let a = value - 0.01;
        let b = 9.99 - value;
        if ((a >= 0 && b >= 0 && num <= 2) || value == 0) {
          callback();
        } else {
          return this.$notify.success({ title: '提示信息', message: rule.message });
        }
      }
      callback();
    },
    // 保留两位小数
    numFilter(value) {
      let realVal = parseFloat(value).toFixed(2);
      return realVal;
    },
    // 改变价格类型,每次改变价格类型时候都会对typePrice 和 listPrice 重新赋值用于计算
    changeType(val) {
      // 成本价
      if (val == 80501001) {
        this.typePrice = val;
        // 判断字段是否为空
        if (this.listType.COST_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.COST_PRICE;
        } else {
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501002) {
        // 销售价
        this.typePrice = val;
        if (this.listType.SALES_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.SALES_PRICE;
        } else {
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501003) {
        // 索赔价
        this.typePrice = val;
        if (this.listType.CLAIM_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.CLAIM_PRICE;
        } else {
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501004) {
        this.typePrice = val;
        // 网点价
        if (this.listType.NODE_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.NODE_PRICE;
        } else {
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501005) {
        this.typePrice = val;
        // 最新进货价
        if (this.listType.LATEST_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.LATEST_PRICE;
        } else {
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501006) {
        // 含税成本价
        this.typePrice = val; // 当时含税成本价对变量赋值，用于金额和参数变动计算
        if (this.listType.COST_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.COST_PRICE + this.listType.COST_PRICE * this.rate;
        } else {
          this.listPrice = 0;
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
        }

        this.changeMoney(this.listPrice);
      } else if (val == 80501007) {
        this.typePrice = val;
        // 终端建议零售价格
        if (this.listType.INSURANCE_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.INSURANCE_PRICE;
        } else {
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }

        this.changeMoney(this.listPrice);
      } else if (val == 80501009) {
        this.typePrice = val;
        // 销售限价
        if (this.listType.LIMIT_PRICE != null) {
          this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.LIMIT_PRICE;
        } else {
          this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      }
    },

    changeMoney(val) {
      if (this.typePrice == 80501006) {
        // 改变含税金额的值
        this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.numFilter(val);
        if (this.listPrice != 0) {
          this.formList2.find(item => item.fieldName === 'PRICE_RATE').initialValue = this.numFilter(val / this.listPrice); // 金额改变时候改变参数
        }
        const num = this.formList2.find(item => item.fieldName === 'PART_QUANTITY').initialValue;
        this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(val * num);
      } else {
        this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.numFilter(val);
        if (this.listPrice != 0) {
          this.formList2.find(item => item.fieldName === 'PRICE_RATE').initialValue = this.numFilter(val / this.listPrice); // 金额改变时候改变参数
        }
        const num = this.formList2.find(item => item.fieldName === 'PART_QUANTITY').initialValue;
        this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(val * num);
      }
    },
    // 改变系数参数
    changecoefficient(val) {
      if (this.typePrice == 80501006) {
        // 改变含税金额的值
        const num = this.formList2.find(item => item.fieldName === 'PART_QUANTITY').initialValue;
        let money = this.numFilter(this.listPrice * val); // 参数改变时候，改变金额
        this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = money;
        this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(money * num);
      } else {
        const num = this.formList2.find(item => item.fieldName === 'PART_QUANTITY').initialValue;
        let money = this.numFilter(this.listPrice * val); // 参数改变时候，改变金额
        this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = money;
        this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(money * num);
      }
    },
    // 改变数量
    changemNum(val) {
      let reg = /^(\-|\+)?([1-9][0-9]*)+(.[0-9]{1,2})?$/;
      let res = String(val).split('.');
      let num = 0;
      if (res[1] != undefined) {
        num = res[1].length;
      }
      if (!reg.test(val) || num > 2) {
        return this.$notify.warning({ title: '提示信息', message: '请输入正确的数值,保留2位小数' });
      } else {
        const money = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue;
        this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(val * money);
      }
    },
    // 关闭弹窗
    closeDialog() {
      this.$emit('close', false);
    },
    tablechangeFun(val) {
      this.tableslist = val;
    },
    // 添加事件提交表单
    confirmHandle() {
      const nums = this.formList2.find(item => item.fieldName === 'PART_QUANTITY').initialValue;
      this.flagS = false;
      let json = this.tableslist[0];
      if (this.tableslist.length == 0) {
        return this.$notify.warning({ title: '提示信息', message: '需选中一条数据' });
      }
      if (this.formList2.find(x => x.fieldName == 'SALES_TYPE').initialValue === 80961002 && this.formList2.find(x => x.fieldName == 'STORAGE_CODE').initialValue === 'OEMK') {
        return this.$notify.warning({ title: '提示信息', message: 'OEM库不能做一进一出操作' });
      }
      if (this.formList2.find(x => x.fieldName == 'SALES_TYPE').initialValue === 80961001) {
        if (json.USEABLE_STOCK - nums < 0) {
          if (json.IS_NEGATIVE == 10041002) {
            return this.$notify.warning({ title: '提示信息', message: '该仓库不允许负库存!' });
          }
        }
      }
      let reg = /^(\-|\+)?([1-9][0-9]*)+(.[0-9]{1,2})?$/;
      let res = String(nums).split('.');
      let num = 0;
      if (res[1] != undefined) {
        num = res[1].length;
      }
      if (!reg.test(nums) || num > 2) {
        return this.$notify.warning({ title: '提示信息', message: '请输入正确的数值,保留2位小数' });
      }
      this.$refs.formpanel2.SUBMIT_FORM();
      let formdata = Object.assign({}, json, this.fromSubmitdata);
      formdata.SALES_TYPE = formdata.SALES_TYPE ? formdata.SALES_TYPE : 80961002;
      if (formdata.PART_SALES_PRICE < formdata.COST_PRICE) {
        this.$confirm('该配件发料价格低于成本价格，是否继续添加配件？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$emit('changedata', formdata);
        });
      } else {
        this.$emit('changedata', formdata);
      }
    }
  }
};
</script>
